define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/cash_auditing/index' + location.search,
                    add_url: 'user/cash_auditing/add',
                    edit_url: 'user/cash_auditing/edit',
                    del_url: 'user/cash_auditing/del',
                    multi_url: 'user/cash_auditing/multi',
                    import_url: 'user/cash_auditing/import',
                    table: 'user_bill',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport:false,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'nickname', title: "昵称",operate: false},
                        {field: 'u.nickname', title: "昵称",visible: false},
                        {field: 'name', title: "姓名",operate: false},
                        {field: 'u.name', title: "姓名",visible: false},
                        {field: 'mobile', title: "电话",operate: false},
                        {field: 'u.mobile', title: "电话",visible: false},
                        {field: 'money', title: "变动金额", operate:'BETWEEN'},
                        {field: 'before', title: "变更前余额", operate:'BETWEEN'},
                        {field: 'after', title: "变更后余额", operate:'BETWEEN'},

                        {field: 'source', title: "来源", searchList: {0:"提现",1:"充值",2:"保障金",3:"佣金"}, formatter: Table.api.formatter.status,operate: false},
                        {field: 'createtime', title: "创建时间", operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'audit_status', title: "审核状态", formatter: Table.api.formatter.status, searchList: {0:'未审核',1:"通过",2:"驳回"},sortable: true},

                        {field: 'operate', title: "审核", table: table, events: Table.api.events.operate, formatter: function(value,row,index){
                                if (row.audit_status==0){
                                    return "<button onclick='shenhe("+row.id+")'   class='shenhe btn-success'>通过</button> <button onclick='bohui("+row.id+")'  class='btn-primary'>驳回</button>"

                                } else {
                                    return ""
                                }
                            }}

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
function shenhe(id){
    layer.confirm(`确定该操作吗？`, {
            title:"审核通过",
            btn: ['确定', '取消'] //按钮
        }, function (index) {
            $.ajax({
                url: "user/cash_auditing/shenhe", //请求接口
                type: "post",
                dataType: "json",
                data: {"id":id}, //请求参数
                success: function (data) {
                    layer.confirm(data.msg, {
                        btn: ['确定'] //按钮
                    }, function (index2) {
                        Fast.api.refreshmenu(); //刷新列表
                        layer.close(index2); //关闭窗口
                    })
                    return false;
                }
            })

        }
    );
}

function bohui(id){
    Layer.prompt({
        title: "审核驳回",
        success: function (layero) {
            $("input", layero).prop("placeholder", "驳回原因");
        }
    }, function (value) {
        Layer.close(Layer.index)
        $.ajax({
            url: "user/cash_auditing/bohui", //请求接口
            type: "post",
            dataType: "json",
            data: {
                "id":id,
                "rejection_info":value
            }, //请求参数
            success: function (data) {
                layer.confirm(data.msg, {
                    btn: ['确定'] //按钮
                }, function (index2) {
                    Fast.api.refreshmenu(); //刷新列表
                    layer.close(index2); //关闭窗口
                })
                return false;
            }
        })
    });
}
